package com.gao.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gao.domain.Product;
import com.gao.service.ProductService;
import com.gao.service.impl.ProductServiceImpl;

/**
 * Servlet implementation class ShowAllProductsServlet
 */
@WebServlet("/ProductsIndexServlet")
public class ProductsIndexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
  
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		ProductService productService  = new ProductServiceImpl();
		List<Product> products = null;
	
		products = productService.getAllProducts();
			
		request.setAttribute("products", products);
		request.getRequestDispatcher("index.jsp").forward(request, response);
	}

}
